package com.ktjiaoyu.ktmall.service.impl;

import com.ktjiaoyu.ktmall.dao.ProductDao;
import com.ktjiaoyu.ktmall.dao.impl.ProductDaoImpl;
import com.ktjiaoyu.ktmall.entity.Product;
import com.ktjiaoyu.ktmall.service.ProductService;

import java.util.List;

/**
 * @author xm
 * @date 2025/9/15
 * @Dome
 */
public class ProductServiceImpl implements ProductService {
    private ProductDao productDao = new ProductDaoImpl();

    @Override
    public List<Product> findList(String title, Long categoryId, int page, int pageSize) {
        return productDao.findList(title, categoryId, page, pageSize);
    }

    @Override
    public int count(String title, Long categoryId) {
        return productDao.count(title, categoryId);
    }

    @Override
    public Product findById(Long id) {
        return productDao.findById(id);
    }

    @Override
    public boolean saveProduct(Product product) {
        if (product.getId() == null) {
            return productDao.insert(product) > 0;
        } else {
            return productDao.update(product) > 0;
        }
    }

    @Override
    public boolean removeById(Long id) {
        return productDao.delete(id) > 0;
    }

    @Override
    public boolean updateStatus(Long id, Integer status) {
        return productDao.updateStatus(id, status) > 0;
    }
}
